"use strict";

module ee.has {

  class GraphCanvas {

	leftPadding: number = 10;
	rightPadding: number = 10;
	topPadding: number = 10;
	bottomPadding: number = 10;
	xAxisPadding: number = 0;

	constructor(public canvas: HTMLCanvasElement) {
            this.setXUnits(this.getX());
            this.setYUnits(this.getY());
	}

        haveCanvas() {
            return this.canvas !== undefined && this.canvas !== null;
        }

	getX() {
	    if(haveCanvas()) {
                this.x = this.canvas.width - this.leftPadding - this.rightPadding;
                this.getX = function () {
                    return this.x;
                }
	    } else {
                this.getX = function () {
                    return -1;
                }
            }
	    return this.getX();
	}

	getY() {
	    if(haveCanvas()) {
                this.y = this.canvas.height - this.topPadding - this.bottomPadding;
                this.getY = function () {
                    return this.y;
                }
		
	    } else {
                this.getY = function () {
                    return -1;
                }
            }
	    return this.getY();
	}

        xUnits:number = 1; // units on axis
        yUnits:number = 1;
        xPixelUnits:number 1; // pixel units
        yPixelUnits:number 1;

        setXUnits(units:number) {
            this.xUnits = units;
            this.xPixelUnits = this.xUnits / this.getX();
        }

        setYUnits(units:number) {
            this.yUnits = units;
            this.yPixelUnits = this.yUnits / this.getY();
        }
    };
}